package thread;

public class ThreadDemo12 {
    private static boolean isQuit = false;
    //如果把它弄成main的局部变量是不行的
    public static void main(String[] args) {
        Thread t = new Thread(() ->{
            while(!isQuit) {
                System.out.println("我是一个正在工作的线程");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("线程执行完毕");
        });

        t.start();
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("结束t线程");
        System.out.println("结束倒计时: 5");
        System.out.println("结束倒计时: 4");
        System.out.println("结束倒计时: 3");
        System.out.println("结束倒计时: 2");
        System.out.println("结束倒计时: 1");//主线程来负责控制
        isQuit = true;
//        System.out.println("结束t线程");


    }
}
